<!doctype html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>Logos: Syntax &middot; Theos</title>
	<meta name="viewport" content="initial-scale=1">
	<meta name="theme-color" content="#382b42">
	<link rel="stylesheet" type="text/css" href="assets/style-c8af8a04be2058be41d4157721a624bcd1543cc5641394fb0e9450c62a04e09d.css">
	<link rel="icon" href="assets/favicon-447ec328b50bd5d64f09e1f06fe07532f924f274bd5de6567a43690bf494c99a.svg" sizes="any" type="image/svg+xml">

</head>

<body>
	<header>
	<div class="container">
		<h1>
			<a href="#">
				<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 781 224">
					<title>Theos</title>
					<path d="M155.2 18.4H2.6v36.3H54V218h47.4V54.7h49.2l4.6-36.3zM263 60.2c-18 0-31.7 7.2-44 21V-.3l-45.6 4.6V218H219V113.2c8-12.4 16.3-19.6 26.4-19.6 8.6 0 14.4 4.3 14.4 20.4v104h45.5V106.3c0-29-16-46-42.4-46zm210 78.3c0 5-.4 11.8-1 16.4h-94.4c2.8 27 15.8 34.2 34.5 34.2 13 0 24-4.3 37-13.6l19 25.4c-15.2 12-35 21.4-59.6 21.4-51 0-77-33-77-80.7 0-45.6 25-82 71.5-82 43.5.3 70.5 29 70.5 78.5zm-44.7-11v-2c-.3-20.7-6.7-35-24.8-35-15.3 0-24 9.4-26.2 37h51zm137-67.3c46.7 0 75 30 75 81.5 0 49-28.3 81.2-75 81.2-46.3 0-74.8-30-74.8-82 0-49 28.2-81 74.8-81zm0 33.4c-18.4 0-27.6 14.7-27.6 47.8 0 34 9.2 48 27.6 48 18.5 0 27.7-14.6 27.7-47.7 0-34-9.2-48-27.7-48zm156-33.4c-38.7 0-62.6 20.4-62.6 46.6 0 23.6 15 39.2 45.2 47.8 27 7.8 32 11 32 21.4 0 9.2-8.8 14.4-22 14.4-15 0-29-6-41-15L651 200c15 14 37.4 23 64 23 38 0 68-18.6 68-50.3 0-27.4-17-40-47.3-48.7-27.3-8-31.4-11.6-31.4-19.7 0-7 6-11.5 18.5-11.5 13 0 25.7 4.3 37.5 11.8l17-25.6c-14-11.6-34-18.8-56-18.8z" fill="currentColor" fill-rule="evenodd"/>
				</svg>
			</a>
		</h1>

		<p class="header-tagline">A cross-platform build system for creating iOS, macOS, Linux, and Windows programs.</p>
	</div>
</header>


	<main>
		<div class="container">
			<div class="row flex-md-row-reverse">
				<article class="col-md-9">
					<h1>Logos: Syntax</h1>
					<p>Logos is a component of the Theos development suite that allows method hooking code to be written easily and clearly, using a set of special preprocessor directives.</p>

<h2 id="top-level">Top Level</h2>

<p>The directives in this category should not exist within a group/hook/subclass block.
An exception is <a href="#hookf">%hookf</a> which can exist in a <a href="#group">%group</a> block.</p>

<h3 id="config">%config</h3>

<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">%</span><span class="n">config</span><span class="p">(</span><span class="n">Key</span><span class="o">=</span><span class="n">Value</span><span class="p">)</span>
</code></pre></div></div>

<p>Set a logos configuration flag.</p>

<h4 id="configuration-flags">Configuration Flags</h4>

<table>
	<thead>
		<tr>
			<th>Key</th>
			<th>Values</th>
			<th>Notes</th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<td rowspan="3">generator</td>
			<td>MobileSubstrate</td>
			<td>generate code that uses <a href="http://www.cydiasubstrate.com/" title="MobileSubstrate">MobileSubstrate</a> for hooking.</td>
		</tr>
		<tr>
			<td>libhooker</td>
			<td>generate code that uses <a href="https://libhooker.com/docs/" title="libhooker">libhooker</a> for hooking.</td>
		</tr>
		<tr>
			<td>internal</td>
			<td>generate code that uses only internal Objective-C runtime methods for hooking. Currently, <a href="#hookf">%hookf</a> is <strong>not</strong> supported in this generator.</td>
		</tr>
		<tr>
			<td rowspan="3">warnings</td>
			<td>none</td>
			<td>suppress all warnings</td>
		</tr>
		<tr>
			<td>default</td>
			<td>non-fatal warnings</td>
		</tr>
		<tr>
			<td>error</td>
			<td>make all warnings fatal</td>
		</tr>
		<tr>
			<td>dump</td>
			<td>yaml</td>
			<td>dump the internal parse tree in YAML format</td>
		</tr>
	</tbody>
</table>

<p>Example:</p>

<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">%</span><span class="n">config</span><span class="p">(</span><span class="n">generator</span><span class="o">=</span><span class="n">internal</span><span class="p">);</span>
</code></pre></div></div>

<h3 id="hookf">%hookf</h3>

<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">%</span><span class="n">hookf</span><span class="p">(</span><span class="k">return</span> <span class="n">type</span><span class="p">,</span> <span class="n">functionName</span><span class="p">,</span> <span class="n">arguments</span> <span class="n">list</span><span class="p">...)</span> <span class="p">{</span>
	<span class="cm">/* body */</span>
<span class="p">}</span>
</code></pre></div></div>

<p>Generate a function hook for the function named <code class="language-plaintext highlighter-rouge">functionName</code>.
Set <code class="language-plaintext highlighter-rouge">functionName</code> in <code class="language-plaintext highlighter-rouge">%init</code> to an expression if the symbol should be dynamically looked up.</p>

<p>Example:</p>

<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">// Given the function prototype (only add it yourself if it's not declared in an included/imported header)</span>

<span class="kt">FILE</span> <span class="o">*</span><span class="nf">fopen</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">path</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">mode</span><span class="p">);</span>

<span class="c1">// The hook is thus made</span>
<span class="o">%</span><span class="n">hookf</span><span class="p">(</span><span class="kt">FILE</span> <span class="o">*</span><span class="p">,</span> <span class="n">fopen</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">path</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">mode</span><span class="p">)</span> <span class="p">{</span>
	<span class="n">puts</span><span class="p">(</span><span class="s">"Hey, we're hooking fopen to deny relative paths!"</span><span class="p">);</span>
	<span class="k">if</span> <span class="p">(</span><span class="n">path</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">!=</span> <span class="sc">'/'</span><span class="p">)</span> <span class="p">{</span>
		<span class="k">return</span> <span class="nb">NULL</span><span class="p">;</span>
	<span class="p">}</span>
	<span class="k">return</span> <span class="o">%</span><span class="n">orig</span><span class="p">;</span> <span class="c1">// Call the original implementation of this function</span>
<span class="p">}</span>

<span class="c1">// functions can also be looked up at runtime, if, for example, the function is in a private framework</span>
<span class="o">%</span><span class="n">hookf</span><span class="p">(</span><span class="n">BOOL</span><span class="p">,</span> <span class="n">MGGetBoolAnswer</span><span class="p">,</span> <span class="n">CFStringRef</span> <span class="n">string</span><span class="p">)</span> <span class="p">{</span>
	<span class="k">if</span> <span class="p">(</span><span class="n">CFEqual</span><span class="p">(</span><span class="n">string</span><span class="p">,</span> <span class="n">CFSTR</span><span class="p">(</span><span class="s">"StarkCapability"</span><span class="p">)))</span> <span class="p">{</span>
		<span class="k">return</span> <span class="nb">YES</span><span class="p">;</span>
	<span class="p">}</span>
	<span class="k">return</span> <span class="o">%</span><span class="n">orig</span><span class="p">;</span>
<span class="p">}</span>
<span class="o">%</span><span class="n">ctor</span> <span class="p">{</span>
	<span class="o">%</span><span class="n">init</span><span class="p">(</span><span class="n">MGGetBoolAnswer</span> <span class="o">=</span> <span class="n">MSFindSymbol</span><span class="p">(</span><span class="nb">NULL</span><span class="p">,</span> <span class="s">"_MGGetBoolAnswer"</span><span class="p">));</span>
<span class="p">}</span>
</code></pre></div></div>

<h3 id="ctor">%ctor</h3>

<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">%</span><span class="n">ctor</span> <span class="p">{</span>
	<span class="cm">/* body */</span>
<span class="p">}</span>
</code></pre></div></div>

<p>Generate an anonymous constructor (of default priority).
This function is executed after the binary is loaded into memory.
<code class="language-plaintext highlighter-rouge">argc</code>, <code class="language-plaintext highlighter-rouge">argv</code>, and <code class="language-plaintext highlighter-rouge">envp</code> are implicit arguments so they can be used as they would be in a <code class="language-plaintext highlighter-rouge">main</code> function.</p>

<h3 id="dtor">%dtor</h3>

<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">%</span><span class="n">dtor</span> <span class="p">{</span>
	<span class="cm">/* body */</span>
<span class="p">}</span>
</code></pre></div></div>

<p>Generate an anonymous deconstructor (of default priority).
This function is executed before the binary is unloaded from memory.
<code class="language-plaintext highlighter-rouge">argc</code>, <code class="language-plaintext highlighter-rouge">argv</code>, and <code class="language-plaintext highlighter-rouge">envp</code> are implicit arguments so they can be used as they would be in a <code class="language-plaintext highlighter-rouge">main</code> function.</p>

<h2 id="block-level">Block level</h2>

<p>The directives in this category open a block of code which must be closed by an <a href="#end">%end</a> directive (shown below).
These should not exist within functions or methods.</p>

<h3 id="group">%group</h3>

<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">%</span><span class="n">group</span> <span class="n">GroupName</span>
<span class="cm">/* %hooks */</span>
<span class="o">%</span><span class="n">end</span>
</code></pre></div></div>

<p>Generate a hook group with the name <code class="language-plaintext highlighter-rouge">GroupName</code>.
Groups can be used for conditional initialization or code organization.
All ungrouped hooks are in the default group, initializable via <a href="#init">%init</a> without arguments.</p>

<p>Cannot be inside another <a href="#group">%group</a> block.</p>

<p>Grouping can be used to manage backwards compatibility with older code.</p>

<p>Example:</p>

<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">%</span><span class="n">group</span> <span class="n">iOS8</span>
<span class="o">%</span><span class="n">hook</span> <span class="n">IOS8_SPECIFIC_CLASS</span>
	<span class="c1">// your code here</span>
<span class="o">%</span><span class="n">end</span> <span class="c1">// end hook</span>
<span class="o">%</span><span class="n">end</span> <span class="c1">// end group ios8</span>

<span class="o">%</span><span class="n">group</span> <span class="n">iOS9</span>
<span class="o">%</span><span class="n">hook</span> <span class="n">IOS9_SPECIFIC_CLASS</span>
	<span class="c1">// your code here</span>
<span class="o">%</span><span class="n">end</span> <span class="c1">// end hook</span>
<span class="o">%</span><span class="n">end</span> <span class="c1">// end group ios9</span>

<span class="o">%</span><span class="n">ctor</span> <span class="p">{</span>
	<span class="k">if</span> <span class="p">(</span><span class="n">kCFCoreFoundationVersionNumber</span> <span class="o">&gt;</span> <span class="mi">1200</span><span class="p">)</span> <span class="p">{</span>
		<span class="o">%</span><span class="n">init</span><span class="p">(</span><span class="n">iOS9</span><span class="p">);</span>
	<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
		<span class="o">%</span><span class="n">init</span><span class="p">(</span><span class="n">iOS8</span><span class="p">);</span>
	<span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div>

<h3 id="hook">%hook</h3>

<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">%</span><span class="n">hook</span> <span class="n">ClassName</span>
<span class="cm">/* objc methods */</span>
<span class="o">%</span><span class="n">end</span>
</code></pre></div></div>

<p>Open a hook block for the class named <code class="language-plaintext highlighter-rouge">ClassName</code>.</p>

<p>Can be inside a <a href="#group">%group</a> block.</p>

<p>Example:</p>

<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">%</span><span class="n">hook</span> <span class="n">SBApplicationController</span>
<span class="k">-</span> <span class="p">(</span><span class="kt">void</span><span class="p">)</span><span class="nf">uninstallApplication</span><span class="p">:(</span><span class="n">SBApplication</span> <span class="o">*</span><span class="p">)</span><span class="nv">application</span> <span class="p">{</span>
	<span class="n">NSLog</span><span class="p">(</span><span class="s">@"Hey, we're hooking uninstallApplication:!"</span><span class="p">);</span>
	<span class="o">%</span><span class="n">orig</span><span class="p">;</span> <span class="c1">// Call the original implementation of this method</span>
<span class="p">}</span>
<span class="o">%</span><span class="n">end</span>
</code></pre></div></div>

<h3 id="new">%new</h3>

<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">%</span><span class="n">new</span>
<span class="cm">/* objc method */</span>
</code></pre></div></div>
<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">%</span><span class="n">new</span><span class="p">(</span><span class="n">signature</span><span class="p">)</span>
<span class="cm">/* objc method */</span>
</code></pre></div></div>

<p>Add a new method to a hooked class or subclass by adding this directive above the method definition.
signature is the Objective-C type encoding for the new method; if it is omitted, one will be generated.</p>

<p>Must be inside a <a href="#hook">%hook</a> or <a href="#subclass">%subclass</a> block.</p>

<p>Example:</p>

<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">%</span><span class="n">new</span>
<span class="k">-</span> <span class="p">(</span><span class="kt">void</span><span class="p">)</span><span class="nf">handleTapGesture</span><span class="p">:(</span><span class="n">UITapGestureRecognizer</span> <span class="o">*</span><span class="p">)</span><span class="nv">gestureRecognizer</span> <span class="p">{</span>
	<span class="n">NSLog</span><span class="p">(</span><span class="s">@"Received tap: %@"</span><span class="p">,</span> <span class="n">gestureRecognizer</span><span class="p">);</span>
<span class="p">}</span>
</code></pre></div></div>

<h3 id="subclass">%subclass</h3>

<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">%</span><span class="n">subclass</span> <span class="n">ClassName</span><span class="o">:</span> <span class="n">Superclass</span> <span class="o">&lt;</span><span class="n">Protocol</span> <span class="n">list</span><span class="o">&gt;</span>
<span class="cm">/* %properties and methods */</span>
<span class="o">%</span><span class="n">end</span>
</code></pre></div></div>

<p>Generate a subclass at runtime.
Like @property in normal Objective-C classes, you can use <a href="#property">%property</a> to add properties to the subclass.
The <a href="#new">%new</a> specifier is needed for a method that doesn’t exist in the superclass.
To instantiate an object of the new class, you can use the <a href="#c">%c</a> operator.</p>

<p>Can be inside a <a href="#group">%group</a> block.</p>

<p>Example:</p>

<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">// An interface is required to be able to call methods of the runtime subclass using block syntax.</span>
<span class="k">@interface</span> <span class="nc">MyObject</span> <span class="p">:</span> <span class="nc">NSObject</span>
<span class="k">@property</span> <span class="p">(</span><span class="n">nonatomic</span><span class="p">,</span> <span class="n">retain</span><span class="p">)</span> <span class="n">NSString</span> <span class="o">*</span> <span class="n">someValue</span><span class="p">;</span>
<span class="k">@end</span>

<span class="o">%</span><span class="n">subclass</span> <span class="n">MyObject</span> <span class="o">:</span> <span class="n">NSObject</span>

<span class="o">%</span><span class="n">property</span> <span class="p">(</span><span class="n">nonatomic</span><span class="p">,</span> <span class="n">retain</span><span class="p">)</span> <span class="n">NSString</span> <span class="o">*</span> <span class="n">someValue</span><span class="p">;</span>

<span class="k">-</span> <span class="p">(</span><span class="n">instancetype</span><span class="p">)</span><span class="n">init</span> <span class="p">{</span>
	<span class="k">if</span> <span class="p">((</span><span class="n">self</span> <span class="o">=</span> <span class="o">%</span><span class="n">orig</span><span class="p">))</span> <span class="p">{</span>
		<span class="p">[</span><span class="n">self</span> <span class="nf">setSomeValue</span><span class="p">:</span><span class="s">@"value"</span><span class="p">];</span>
	<span class="p">}</span>
	<span class="k">return</span> <span class="n">self</span><span class="p">;</span>
<span class="p">}</span>

<span class="o">%</span><span class="n">end</span>

<span class="o">%</span><span class="n">ctor</span> <span class="p">{</span>
	<span class="c1">// The runtime subclass cannot be linked at compile time so you have to use %c().</span>
	<span class="n">MyObject</span> <span class="o">*</span><span class="n">myObject</span> <span class="o">=</span> <span class="p">[[</span><span class="o">%</span><span class="n">c</span><span class="p">(</span><span class="n">MyObject</span><span class="p">)</span> <span class="nf">alloc</span><span class="p">]</span> <span class="nf">init</span><span class="p">];</span>
	<span class="n">NSLog</span><span class="p">(</span><span class="s">@"myObject: %@"</span><span class="p">,</span> <span class="p">[</span><span class="n">myObject</span> <span class="nf">someValue</span><span class="p">]);</span>
<span class="p">}</span>
</code></pre></div></div>

<h3 id="property">%property</h3>

<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">%</span><span class="n">property</span> <span class="p">(</span><span class="n">nonatomic</span><span class="o">|</span><span class="n">assign</span><span class="o">|</span><span class="n">retain</span><span class="o">|</span><span class="n">copy</span><span class="o">|</span><span class="n">weak</span><span class="o">|</span><span class="n">strong</span><span class="o">|</span><span class="n">getter</span><span class="o">=</span><span class="p">...</span><span class="o">|</span><span class="n">setter</span><span class="o">=</span><span class="p">...)</span> <span class="n">Type</span> <span class="n">name</span><span class="p">;</span>
</code></pre></div></div>

<p>Add a property to a <a href="#subclass">%subclass</a> just like you would with @property to a normal Objective-C subclass as well as adding new properties to existing classes within <a href="#hook">%hook</a>.</p>

<p>Must be inside a <a href="#hook">%hook</a> or <a href="#subclass">%subclass</a> block.</p>

<h3 id="end">%end</h3>

<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">%</span><span class="n">end</span>
</code></pre></div></div>

<p>Close a <a href="#group">%group</a>, <a href="#hook">%hook</a> or <a href="#subclass">%subclass</a> block.</p>

<h2 id="function-level">Function level</h2>

<p>The directives in this category should only exist within a function or method body.</p>

<h3 id="init">%init</h3>

<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">%</span><span class="n">init</span><span class="p">;</span>
</code></pre></div></div>
<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">%</span><span class="n">init</span><span class="p">([</span><span class="o">&lt;</span><span class="n">ClassName</span><span class="o">&gt;=&lt;</span><span class="n">expr</span><span class="o">&gt;</span><span class="p">,</span> <span class="err">…</span><span class="p">]);</span>
</code></pre></div></div>
<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">%</span><span class="n">init</span><span class="p">(</span><span class="n">GroupName</span><span class="p">[,</span> <span class="p">[</span><span class="o">+|-</span><span class="p">]</span><span class="o">&lt;</span><span class="n">ClassName</span><span class="o">&gt;=&lt;</span><span class="n">expr</span><span class="o">&gt;</span><span class="p">,</span> <span class="err">…</span><span class="p">]);</span>
</code></pre></div></div>

<p>Initialize a group’s method and function hooks.
Passing no group name will initialize the default group.
Passing <code class="language-plaintext highlighter-rouge">ClassName=expr</code> arguments will substitute the given expressions for those classes at initialization time.
The <code class="language-plaintext highlighter-rouge">+</code> sigil (as in class methods in Objective-C) can be prepended to the classname to substitute an expression for the metaclass.
If not specified, the sigil defaults to <code class="language-plaintext highlighter-rouge">-</code>, to substitute the class itself.
If not specified, the metaclass is derived from the class.</p>

<p>The class name replacement is specially useful for classes that contain characters that can’t be used as the class name token for the <a href="#hook">%hook</a> directive, such as spaces and dots.</p>

<p>Example:</p>

<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">%</span><span class="n">hook</span> <span class="n">ClassName</span>
<span class="k">-</span> <span class="p">(</span><span class="n">id</span><span class="p">)</span><span class="n">init</span> <span class="p">{</span>
	<span class="k">return</span> <span class="o">%</span><span class="n">orig</span><span class="p">;</span>
<span class="p">}</span>
<span class="o">%</span><span class="n">end</span>

<span class="o">%</span><span class="n">ctor</span> <span class="p">{</span>
	<span class="o">%</span><span class="n">init</span><span class="p">(</span><span class="n">ClassName</span><span class="o">=</span><span class="n">objc_getClass</span><span class="p">(</span><span class="s">"SwiftApp.ClassName"</span><span class="p">));</span>
<span class="p">}</span>
</code></pre></div></div>

<h3 id="c">%c</h3>

<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">%</span><span class="n">c</span><span class="p">([</span><span class="o">+|-</span><span class="p">]</span><span class="n">ClassName</span><span class="p">)</span>
</code></pre></div></div>

<p>Evaluates to <code class="language-plaintext highlighter-rouge">ClassName</code> at runtime.
If the <code class="language-plaintext highlighter-rouge">+</code> sigil is specified, it evaluates to MetaClass instead of Class.
If not specified, the sigil defaults to <code class="language-plaintext highlighter-rouge">-</code>, evaluating to Class.</p>

<h3 id="orig">%orig</h3>

<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">%</span><span class="n">orig</span>
</code></pre></div></div>
<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">%</span><span class="n">orig</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="err">…</span><span class="p">)</span>
</code></pre></div></div>

<p>Call the original hooked function or method.
Doesn’t work in a <a href="#new">%new</a>‘d method.
Works in subclasses, strangely enough, because MobileSubstrate will generate a super-call closure at hook time.
(If the hooked method doesn’t exist in the class we’re hooking, it creates a stub that just calls the superclass implementation.) <code class="language-plaintext highlighter-rouge">args</code> is passed to the original function - don’t include <code class="language-plaintext highlighter-rouge">self</code> and <code class="language-plaintext highlighter-rouge">_cmd</code>, Logos does this for you.</p>

<p>Example:</p>

<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">%</span><span class="n">hook</span> <span class="n">ClassName</span>
<span class="k">-</span> <span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="nf">add</span><span class="p">:(</span><span class="kt">int</span><span class="p">)</span><span class="nv">a</span> <span class="nf">to</span><span class="p">:(</span><span class="kt">int</span><span class="p">)</span><span class="nv">b</span> <span class="p">{</span>
	<span class="k">if</span> <span class="p">(</span><span class="n">a</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
		<span class="c1">// Return original result if `a` is not 0</span>
		<span class="k">return</span> <span class="o">%</span><span class="n">orig</span><span class="p">;</span>
	<span class="p">}</span>
	<span class="c1">// Otherwise, use 1 as `a`</span>
	<span class="k">return</span> <span class="o">%</span><span class="n">orig</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">b</span><span class="p">);</span>
<span class="p">}</span>
<span class="o">%</span><span class="n">end</span>
</code></pre></div></div>

<h4 id="orig-1">&amp;%orig</h4>

<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">&amp;%</span><span class="n">orig</span>
</code></pre></div></div>

<p>Get a pointer to the original function or method.
Return type is <code class="language-plaintext highlighter-rouge">void (*)(id, SEL[, arg types])</code></p>

<p>Example:</p>

<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">// Call from outside hooked method:</span>
<span class="kt">void</span> <span class="p">(</span><span class="o">*</span><span class="n">orig_ClassName_start</span><span class="p">)(</span><span class="n">id</span><span class="p">,</span> <span class="n">SEL</span><span class="p">)</span> <span class="o">=</span> <span class="nb">nil</span><span class="p">;</span>

<span class="kt">void</span> <span class="nf">doStuff</span><span class="p">(</span><span class="n">id</span> <span class="n">self</span><span class="p">,</span> <span class="n">SEL</span> <span class="n">_cmd</span><span class="p">)</span> <span class="p">{</span>
	<span class="k">if</span> <span class="p">(</span><span class="n">self</span> <span class="o">&amp;&amp;</span> <span class="n">orig_ClassName_start</span><span class="p">)</span> <span class="p">{</span>
		<span class="n">orig_ClassName_start</span><span class="p">(</span><span class="n">self</span><span class="p">,</span> <span class="n">_cmd</span><span class="p">);</span>
	<span class="p">}</span>
<span class="p">}</span>

<span class="o">%</span><span class="n">hook</span> <span class="n">ClassName</span>
<span class="k">-</span> <span class="p">(</span><span class="kt">void</span><span class="p">)</span><span class="n">start</span> <span class="p">{</span>
	<span class="o">%</span><span class="n">orig</span><span class="p">;</span>
	<span class="n">orig_ClassName_start</span> <span class="o">=</span> <span class="o">&amp;%</span><span class="n">orig</span><span class="p">;</span>
	<span class="n">dispatch_after</span><span class="p">(</span><span class="n">dispatch_time</span><span class="p">(</span><span class="n">DISPATCH_TIME_NOW</span><span class="p">,</span> <span class="mi">1</span> <span class="o">*</span> <span class="n">NSEC_PER_SEC</span><span class="p">),</span>
		<span class="n">dispatch_get_main_queue</span><span class="p">(),</span> <span class="o">^</span><span class="p">{</span>
			<span class="n">doStuff</span><span class="p">(</span><span class="n">self</span><span class="p">,</span> <span class="n">_cmd</span><span class="p">);</span>
	<span class="p">});</span>
<span class="p">}</span>
<span class="o">%</span><span class="n">end</span>

<span class="c1">// Call with another object:</span>
<span class="o">%</span><span class="n">hook</span> <span class="n">ClassName</span>
<span class="k">-</span> <span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="nf">add</span><span class="p">:(</span><span class="kt">int</span><span class="p">)</span><span class="nv">a</span> <span class="nf">to</span><span class="p">:(</span><span class="kt">int</span><span class="p">)</span><span class="nv">b</span> <span class="p">{</span>
	<span class="kt">int</span> <span class="p">(</span><span class="o">*</span><span class="n">_orig</span><span class="p">)(</span><span class="n">id</span><span class="p">,</span> <span class="n">SEL</span><span class="p">,</span> <span class="kt">int</span><span class="p">,</span> <span class="kt">int</span><span class="p">)</span> <span class="o">=</span> <span class="o">&amp;%</span><span class="n">orig</span><span class="p">;</span>
	<span class="n">ClassName</span> <span class="o">*</span> <span class="n">myObject</span> <span class="o">=</span> <span class="p">[</span><span class="n">ClassName</span> <span class="nf">new</span><span class="p">];</span>
	<span class="kt">int</span> <span class="n">r</span> <span class="o">=</span> <span class="n">_orig</span><span class="p">(</span><span class="n">myObject</span><span class="p">,</span> <span class="n">_cmd</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">);</span>
	<span class="p">[</span><span class="n">myObject</span> <span class="nf">release</span><span class="p">];</span>
	<span class="k">return</span> <span class="n">r</span><span class="p">;</span>
<span class="p">}</span>
<span class="o">%</span><span class="n">end</span>
</code></pre></div></div>

<p>Real world example at <a href="https://github.com/DHowett/preferenceloader/blob/master/prefs.xm#L237-L263">PreferenceLoader</a></p>

<h3 id="log">%log</h3>

<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">%</span><span class="n">log</span><span class="p">;</span>
</code></pre></div></div>
<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">%</span><span class="n">log</span><span class="p">([(</span><span class="o">&lt;</span><span class="n">type</span><span class="o">&gt;</span><span class="p">)</span><span class="o">&lt;</span><span class="n">expr</span><span class="o">&gt;</span><span class="p">,</span> <span class="err">…</span><span class="p">]);</span>
</code></pre></div></div>

<p>Dump the method arguments to syslog.
Typed arguments included in <code class="language-plaintext highlighter-rouge">%log</code> will be logged as well.</p>

				</article>

				<aside class="col-md-3">
					<ul>
  
  <li>
    
      <a href="./index.html">Home</a>
    
    
  </li>
  
  <li>
    
      <a href="./Installation.html">Installation</a>
    
    
      <ul>
        
          <li>
            <a href="./Installation-iOS.html">
              iOS
              
            </a>
          </li>
        
          <li>
            <a href="./Installation-macOS.html">
              macOS
              
            </a>
          </li>
        
          <li>
            <a href="./Installation-Linux.html">
              Linux & Windows
              
            </a>
          </li>
        
          <li>
            <a href="./Upgrading-from-legacy-Theos.html">
              Upgrading from legacy Theos
              
            </a>
          </li>
        
      </ul>
    
  </li>
  
  <li>
    
      <span>Usage</span>
    
    
      <ul>
        
          <li>
            <a href="./Concepts.html">
              Concepts
              
            </a>
          </li>
        
          <li>
            <a href="./Configuration.html">
              Configuration
              
            </a>
          </li>
        
          <li>
            <a href="./Commands.html">
              Commands
              
            </a>
          </li>
        
          <li>
            <a href="./Packaging.html">
              Packaging
              
            </a>
          </li>
        
      </ul>
    
  </li>
  
  <li>
    
      <a href="./Features.html">Features</a>
    
    
      <ul>
        
          <li>
            <a href="./NIC.html">
              NIC
              
            </a>
          </li>
        
          <li>
            <a href="./NIC-Syntax.html">
              NIC Syntax
              
            </a>
          </li>
        
          <li>
            <a href="./dm.pl.html">
              dm.pl
              
            </a>
          </li>
        
          <li>
            <a href="./Swift.html">
              Swift
              
            </a>
          </li>
        
          <li>
            <a href="./Modules.html">
              Modules
              
            </a>
          </li>
        
      </ul>
    
  </li>
  
  <li>
    
      <span>Tweak Development</span>
    
    
      <ul>
        
          <li>
            <a href="./Logos.html">
              Logos
              
            </a>
          </li>
        
          <li>
            <a href="./Logos-Syntax.html">
              Logos Syntax
              
            </a>
          </li>
        
          <li>
            <a href="./logify.pl.html">
              Logify
              
            </a>
          </li>
        
          <li>
            <a href="./Logos-File-Extensions.html">
              File Extensions
              
            </a>
          </li>
        
          <li>
            <a href="./Logos-Hook-Splitting.html">
              Hook Splitting
              
            </a>
          </li>
        
          <li>
            <a href="https://orion.theos.dev/" target="_blank" rel="noopener">
              Orion
              
                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 12 12" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
                  <path d="M1 11L11 1"/>
                  <path d="M2.5 1H11V9.5"/>
                </svg>
              
            </a>
          </li>
        
          <li>
            <a href="./Rootless.html">
              Rootless
              
            </a>
          </li>
        
      </ul>
    
  </li>
  
  <li>
    
      <span>Technical</span>
    
    
      <ul>
        
          <li>
            <a href="./Structure.html">
              Structure
              
            </a>
          </li>
        
          <li>
            <a href="./Variables.html">
              Variables
              
            </a>
          </li>
        
      </ul>
    
  </li>
  
  <li>
    
      <a href="./Help.html">Help</a>
    
    
      <ul>
        
          <li>
            <a href="./FAQ.html">
              FAQ
              
            </a>
          </li>
        
          <li>
            <a href="./Parallel-Building.html">
              Parallel Building
              
            </a>
          </li>
        
          <li>
            <a href="./arm64e-Deployment.html">
              arm64e Deployment
              
            </a>
          </li>
        
          <li>
            <a href="./License.html">
              License
              
            </a>
          </li>
        
      </ul>
    
  </li>
  
  <li>
    
      <span>See also</span>
    
    
      <ul>
        
          <li>
            <a href="https://theapplewiki.com/" target="_blank" rel="noopener">
              The Apple Wiki
              
                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 12 12" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
                  <path d="M1 11L11 1"/>
                  <path d="M2.5 1H11V9.5"/>
                </svg>
              
            </a>
          </li>
        
          <li>
            <a href="https://www.reddit.com/r/jailbreakdevelopers" target="_blank" rel="noopener">
              /r/jailbreakdevelopers
              
                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 12 12" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
                  <path d="M1 11L11 1"/>
                  <path d="M2.5 1H11V9.5"/>
                </svg>
              
            </a>
          </li>
        
          <li>
            <a href="https://github.com/theiostream/theos-ref" target="_blank" rel="noopener">
              theos-ref (legacy docs)
              
                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 12 12" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
                  <path d="M1 11L11 1"/>
                  <path d="M2.5 1H11V9.5"/>
                </svg>
              
            </a>
          </li>
        
      </ul>
    
  </li>
  
</ul>

				</aside>
			</div>
		</div>
	</main>

	<footer role="navigation">
	<ul class="footer-sub-links">
		<li><a href="./">Docs</a></li>
		<li><a href="./Help.html">Get Help</a></li>
		<li><a href="https://github.com/theos" rel="me">GitHub</a></li>
		<li><a href="https://procursus.social/@theos" rel="me">@theos@procursus.social</a></li>
		<li><a href="https://twitter.com/theosdev" rel="me">@theosdev</a></li>
		<li><a href="/discord">Discord</a></li>
	</ul>

	<div class="footer-legal">
		Copyright &copy; Theos.
		<br>
		<a href="https://github.com/theos/theos.dev">Edit on GitHub</a>
	</div>
</footer>

</body>
</html>
